﻿<!--
// ****************************************************************************
// <author>mishkin Ivan</author>
// <email>Mishkin_Ivan@mail.ru</email>
// <date>28.01.2015</date>
// <project>ItemsFilter</project>
// <license> GNU General Public License version 3 (GPLv3) </license>
// ****************************************************************************
-->
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
                    xmlns:bsFilter="http://schemas.bolapansoft.com/xaml/Controls/ItemsFilter"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:model="clr-namespace:Northwind.NET.EF6Model;assembly=Northwind.NET.EF6Model"
                    xmlns:vm="clr-namespace:Northwind.NET.Sample.ViewModel"
                    xmlns:vw="clr-namespace:Northwind.NET.Sample.View"
                    mc:Ignorable="d">
    <LinearGradientBrush x:Key="ButtonNormalBackground" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Offset="0" Color="#F3F3F3" />
        <GradientStop Offset="0.5" Color="#EBEBEB" />
        <GradientStop Offset="0.5" Color="#DDDDDD" />
        <GradientStop Offset="1" Color="#CDCDCD" />
    </LinearGradientBrush>
    <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070" />
    <!--  Resource dictionary entries should be defined here.  -->
    <Geometry x:Key="DownArrowGeometry">M 0 0 L 3.5 4 L 7 0 Z</Geometry>
    <Style x:Key="ComboBoxReadonlyToggleButton" TargetType="{x:Type ToggleButton}">
        <Setter Property="OverridesDefaultStyle" Value="true" />
        <Setter Property="IsTabStop" Value="false" />
        <Setter Property="Focusable" Value="false" />
        <Setter Property="ClickMode" Value="Press" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Themes:ButtonChrome x:Name="Chrome"
                                         Background="{TemplateBinding Background}"
                                         BorderBrush="{TemplateBinding BorderBrush}"
                                         RenderMouseOver="{TemplateBinding IsMouseOver}"
                                         RenderPressed="{TemplateBinding IsPressed}"
                                         SnapsToDevicePixels="true">
                        <Grid Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" HorizontalAlignment="Right">
                            <Path x:Name="Arrow"
                                  Margin="3,1,0,0"
                                  HorizontalAlignment="Center"
                                  VerticalAlignment="Center"
                                  Data="{StaticResource DownArrowGeometry}"
                                  Fill="Black" />
                        </Grid>
                    </Themes:ButtonChrome>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="true">
                            <Setter TargetName="Chrome" Property="RenderPressed" Value="true" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="Arrow" Property="Fill" Value="#AFAFAF" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <LinearGradientBrush x:Key="TextBoxBorder" MappingMode="Absolute" StartPoint="0,0" EndPoint="0,20">
        <GradientStop Offset="0.05" Color="#ABADB3" />
        <GradientStop Offset="0.07" Color="#E2E3EA" />
        <GradientStop Offset="1" Color="#E3E9EF" />
    </LinearGradientBrush>
    <ControlTemplate x:Key="StringFilterViewControlTemplate" TargetType="{x:Type bsFilter:StringFilterView}">
        <Border Height="Auto"
                Margin="{TemplateBinding Margin}"
                HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                VerticalAlignment="{TemplateBinding VerticalAlignment}">
            <Border.Style>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="BorderBrush" Value="#FF9D5C5C" />
                    <Setter Property="CornerRadius" Value="2" />
                    <Setter Property="BorderThickness" Value="1" />
                    <Setter Property="Width" Value="Auto" />
                    <Setter Property="MinWidth" Value="300" />
                    <Setter Property="Background">
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="0.5,1" EndPoint="0.5,0">
                                <GradientStop Color="#FFFEFEFE" />
                                <GradientStop Offset="1" Color="#FFD1D1F1" />
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Border.Style>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBlock Margin="3"
                           HorizontalAlignment="Right"
                           VerticalAlignment="Center"
                           Foreground="{DynamicResource FilterPressedPenColor}"
                           Text="QuickFilter:"
                           TextWrapping="Wrap" />
                <TextBox x:Name="PART_Input"
                         Grid.Column="1"
                         MinWidth="80"
                         Margin="1"
                         Padding="1"
                         Text="{Binding Model.Value,
                                        Mode=TwoWay,
                                        RelativeSource={RelativeSource TemplatedParent},
                                        UpdateSourceTrigger=PropertyChanged}"
                         TextWrapping="NoWrap" />
                <Button Grid.Column="1"
                        HorizontalAlignment="Right"
                        HorizontalContentAlignment="Center"
                        Style="{DynamicResource FilterClearButtonStyle}" />
                <TextBlock Grid.Column="2"
                           Margin="3"
                           VerticalAlignment="Center"
                           FontFamily="/Northwind.NET.Sample;component/Fonts/#Vijaya"
                           FontSize="13.333"
                           Foreground="{DynamicResource FilterPressedPenColor}">
                    Find in Code, Name, ContactName, etc.
                </TextBlock>
            </Grid>
        </Border>
    </ControlTemplate>
    <Style x:Key="CustomerComboBox_StringFilterStyle" TargetType="{x:Type bsFilter:StringFilterView}">
        <Setter Property="Template" Value="{StaticResource StringFilterViewControlTemplate}" />

    </Style>

    <DataTemplate x:Key="CustomerDataTemplate" DataType="{x:Type model:Customer}">
        <Border Grid.Row="0"
                Grid.ColumnSpan="1"
                BorderBrush="{DynamicResource {x:Static SystemColors.MenuHighlightBrushKey}}"
                BorderThickness="1"
                CornerRadius="5"
                Padding="2"
                d:DataContext="{d:DesignData Source=../SampleData/Customer.xaml}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBlock Grid.ColumnSpan="2"
                           Margin="5,0"
                           Block.TextAlignment="Center"
                           FontFamily="Century"
                           FontSize="13.333">
                    <Bold><Run Text="{Binding Name}" />
                    </Bold>
                </TextBlock>
                <TextBlock Grid.Row="1"
                           Margin="10,0"
                           FontFamily="Century"
                           FontSize="12"
                           LineStackingStrategy="BlockLineHeight"><Run Text="{Binding Country}" /><Run Text=" " /><Run Text=",   " /><Run Text=" " /><Run Text="{Binding City}" />
                    <LineBreak />
                    <Italic><Run FontFamily="Times New Roman" Text="{Binding ContactTitle}" />
                    </Italic><Run Text=" " /><Run Text="  " /><Run Text=" " />
                    <Bold><Run Text="{Binding ContactName}" />
                    </Bold>
                </TextBlock>
            </Grid>
        </Border>
    </DataTemplate>
    <Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}">
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBox}">
                    <Grid x:Name="MainGrid" SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="0" MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" />
                        </Grid.ColumnDefinitions>
                        <Popup x:Name="PART_Popup"
                               Grid.ColumnSpan="2"
                               Margin="1"
                               AllowsTransparency="true"
                               IsOpen="{Binding IsDropDownOpen,
                                                RelativeSource={RelativeSource TemplatedParent}}"
                               Placement="Bottom"
                               PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
                            <Themes:SystemDropShadowChrome x:Name="Shdw"
                                                           MinWidth="{Binding ActualWidth,
                                                                              ElementName=MainGrid}"
                                                           MaxHeight="{TemplateBinding MaxDropDownHeight}"
                                                           Color="Transparent">
                                <Border x:Name="DropDownBorder"
                                        Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
                                        BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
                                        BorderThickness="1">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <bsFilter:FilterControl Key="CustomerAnyFieldFilter"
                                                                Height="25"
                                                                MinWidth="300"
                                                                HorizontalAlignment="Left"
                                                                ParentCollection="{TemplateBinding ItemsSource}">
                                            <bsFilter:FilterControl.Resources>
                                                <Style BasedOn="{StaticResource CustomerComboBox_StringFilterStyle}" TargetType="{x:Type bsFilter:StringFilterView}" />
                                            </bsFilter:FilterControl.Resources>
                                            <bsFilter:FilterControl.FilterInitializersManager>
                                                <!--<bsFilter:FilterInitializersManager>
                                                    <vm:CustomersComboBoxFilterInitializer />
                                                </bsFilter:FilterInitializersManager>-->
                                                <vw:CustomersComboBoxFIM></vw:CustomersComboBoxFIM>
                                            </bsFilter:FilterControl.FilterInitializersManager>
                                        </bsFilter:FilterControl>
                                        <ScrollViewer Grid.Row="1" CanContentScroll="true">
                                            <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                        </ScrollViewer>

                                    </Grid>
                                </Border>
                            </Themes:SystemDropShadowChrome>
                        </Popup>
                        <ToggleButton Grid.ColumnSpan="2"
                                      Background="{TemplateBinding Background}"
                                      BorderBrush="{TemplateBinding BorderBrush}"
                                      IsChecked="{Binding IsDropDownOpen,
                                                          Mode=TwoWay,
                                                          RelativeSource={RelativeSource TemplatedParent}}"
                                      Style="{StaticResource ComboBoxReadonlyToggleButton}" />


                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="PART_Popup" Property="HasDropShadow" Value="true">
                            <Setter TargetName="Shdw" Property="Margin" Value="0,0,5,5" />
                            <Setter TargetName="Shdw" Property="Color" Value="#71000000" />
                        </Trigger>
                        <Trigger Property="HasItems" Value="false">
                            <Setter TargetName="DropDownBorder" Property="Height" Value="95" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                            <Setter Property="Background" Value="#FFF4F4F4" />
                        </Trigger>
                        <Trigger Property="IsGrouping" Value="true">
                            <Setter Property="ScrollViewer.CanContentScroll" Value="false" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemTemplate" Value="{StaticResource CustomerDataTemplate}" />
        <Setter Property="IsSynchronizedWithCurrentItem" Value="False" />
        <Setter Property="IsReadOnly" Value="False" />

    </Style>


</ResourceDictionary>